//
//  CompanyMembersVC.m
//  NtoccShipper
//
//  Created by mac on 2020/1/9.
//  Copyright © 2020 zhuchongjin. All rights reserved.
//

#import "CompanyMembersVC.h"
#import "CompanyMembersListVC.h"
#import "AddCompanyMembersVC.h"

@interface CompanyMembersVC ()

@end

@implementation CompanyMembersVC
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.tintColor = [UIColor cjMainTextColor];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    // Do any additional setup after loading the view.
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont cjTitleFont18];
    titleLabel.textColor = [UIColor cjMainTextColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"公司成员";
    self.navigationItem.titleView = titleLabel;
    
    UIImage *img = [[UIImage imageNamed:@"zcj_arrow_back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStyleDone target:self action:@selector(leftBarBtnClicked)];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIButton *myButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [myButton setTitle:@"添加成员" forState:(UIControlStateNormal)];
    myButton.titleLabel.font = [UIFont systemFontOfSize:15];
    UIBarButtonItem *reightItem = [[UIBarButtonItem alloc] initWithCustomView:myButton];
    [myButton addTarget:self action:@selector(addCompanyMenber) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.rightBarButtonItem = reightItem;
    self.navigationController.navigationBar.barTintColor = [UIColor cjWhiteColor];

    self.menuViewStyle = WMMenuViewStyleLine;
    self.titleSizeSelected = 16;
    self.titleSizeNormal = 14;
    self.automaticallyCalculatesItemWidths = YES;
    self.itemMargin = 10;
    self.progressHeight = 2;
    self.progressViewIsNaughty = YES;
    
    self.titleColorNormal = [UIColor cjMainTextColor];
    self.titleColorSelected = [UIColor cjMainColor];

    self.showOnNavigationBar = NO;
    //    [self reloadData];
    [super viewDidLoad];

}

- (void)leftBarBtnClicked{
     [self.navigationController popViewControllerAnimated:YES];
}

- (void)addCompanyMenber{
    AddCompanyMembersVC *vc = [AddCompanyMembersVC new];
    vc.isChange = NO;
    vc.listModel = self.listCompanyModel;
    if ([vc isKindOfClass:[UIViewController class]] == NO) return ;
    if (self.navigationController == nil) return ;
    if (vc.hidesBottomBarWhenPushed == NO) {
        vc.hidesBottomBarWhenPushed = YES;
    }
    
    [self.navigationController pushViewController:vc animated:YES];
  
}
//1、返回分页数量，可以再这里设置标题栏各种样式
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.listCompanyModel.count;
}

//3、把标题与分页对应起来
- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    CompanyMembersModel *model = self.listCompanyModel[index];
    return model.roleName;
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    CompanyMembersModel *model = self.listCompanyModel[index];

    CompanyMembersListVC* vc  = [[CompanyMembersListVC alloc]init];
    vc.indexPage = model.type;
    vc.strRoleCode = model.code;
    vc.strRole = model.role;
    vc.strRoleName = model.roleName;
    return vc;
    
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat width = [super menuView:menu widthForItemAtIndex:index];
    return width  ;
}

///**
// 点击菜单项后会调用本方法
// */
//- (void)menuView:(WMMenuView *)menu didSelectedIndex:(NSInteger)index currentIndex:(NSInteger)currentIndex{
//    [super menuView:menu didSelectedIndex:index currentIndex:currentIndex];
//}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    
    menuView.backgroundColor = [UIColor clearColor];
    //    CGFloat leftMargin = self.showOnNavigationBar ? 0 : 0;
//    CGFloat originY = self.showOnNavigationBar ? 0 : CGRectGetMaxY(self.navigationController.navigationBar.frame);
    return CGRectMake(0, kTopHeight, self.view.frame.size.width, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView{
    
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
